//
//  PhotoPreview.m
//  LoansPresident
//
//  Created by fh on 2018/11/30.
//  Copyright © 2018年 fh. All rights reserved.
//

#import "PhotoPreview.h"

@interface PhotoPreview ()
@end

@implementation PhotoPreview

#pragma mark - Life
- (void)dealloc {
#ifdef DEBUG
    NSLog(@"%@ 释放了",[self class]);
#endif
}
- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor blackColor];
        [self addSubview:self.imgPreview];
        [self addSubview:self.retakeButton];
        [self addSubview:self.useImgButton];
    }
    return self;
}
- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    self.imgPreview.frame = CGRectMake(0, frame.size.height * 0.06, frame.size.width,frame.size.height*(1-0.06-0.18));
    self.retakeButton.frame = CGRectMake(20, CGRectGetMaxY(self.imgPreview.frame), frame.size.height * 0.18, frame.size.height * 0.18);
    self.useImgButton.frame = CGRectMake(frame.size.width-20-frame.size.height * 0.18, CGRectGetMaxY(self.imgPreview.frame), frame.size.height * 0.18, frame.size.height * 0.18);
}

#pragma mark - Event
- (void)useImgButtonAction:(UIButton *)button {
    if (self.useImgButtonClickBlock) {
        self.useImgButtonClickBlock(button);
    }
}
- (void)retakeButtonAction:(UIButton *)button {
    if (self.retakeButtonClickBlock) {
        self.retakeButtonClickBlock(button);
    }
}

#pragma mark - Setter and getter
- (UIButton *)retakeButton {
    if (!_retakeButton) {
        _retakeButton = [UIButton new];
        [_retakeButton setTitle:@"重拍" forState:UIControlStateNormal];
        [_retakeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _retakeButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [_retakeButton addTarget:self action:@selector(retakeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _retakeButton;
}
- (UIButton *)useImgButton {
    if (!_useImgButton) {
        _useImgButton = [UIButton new];
        [_useImgButton setTitle:@"使用照片" forState:UIControlStateNormal];
        [_useImgButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _useImgButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [_useImgButton addTarget:self action:@selector(useImgButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _useImgButton;
}
- (UIImageView *)imgPreview {
    if (!_imgPreview) {
        _imgPreview = [UIImageView new];
        _imgPreview.contentMode = UIViewContentModeScaleAspectFit;
        _imgPreview.backgroundColor = [UIColor blackColor];
    }
    return _imgPreview;
}

@end
